<template>
  <div  style="padding-bottom: 20px; min-width: 1500px;"  v-if="sliders">
    <el-carousel height="250px" arrow="never" indicator-position="none">
      <el-carousel-item v-for="item in sliders" :key="item.title">
        <img :src="item.imgUrl" alt="" style="height:100%; width: 100%; ">
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<script>
import { ref } from 'vue'
import { findBanner } from '@/api/home.js'
import Message from '@/components/library/Message'
import { useRouter } from 'vue-router'
export default {
  name: 'HomeBanner',
  setup () {
    const router = useRouter()
    function toLogin () {
      router.push({ path: '/login' })
    }
    // 调用模拟的接口  获取轮播图数据
    const sliders = ref([])
    findBanner().then(res => {
      if (res.code === '999') {
        Message({ type: 'error', text: res.msg })
        toLogin()
      }
      if (res.code === '200')sliders.value = res.data[0].bannerList
      // console.log(res.data)
    }).catch(err => {
      console.log(err)
    })
    return { sliders }
  }

}
</script>

<style>

</style>
